package org.getOffer.offer05;

/**
 * @Author: wjy
 * @Date: 2021/9/23 10:11
 */
public class Solution {

    public static void main(String[] args) {
        //String s = "We are happy.";
        String s = "  ";
        replaceSpace(s);
    }

    public static String replaceSpace(String s) {

        if (s.length() == 0) {
            return "";
        }

        char[] chars = s.toCharArray();

        System.out.println(chars.length);

        StringBuilder stringBuilder = new StringBuilder();

        for (char c : chars) {

            if (c != ' ') {
                stringBuilder.append(String.valueOf(c));
            } else {
                stringBuilder.append("%20");
            }
        }

        System.out.println(stringBuilder.toString());

        return stringBuilder.toString();
    }

}
